/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef RESPAWNER_H
#define RESPAWNER_H

#include <memory>

#include "MudObject.h"

namespace Chronos {

class Respawner : public MudObjectListener {
public:
    Respawner(unsigned int delay_);
    virtual bool handleObjectEvent(MudObject& object, MudObjectEvent event);
    virtual void spawn() = 0;
protected:
    unsigned int delay;
private:
    Respawner(const Respawner&);
    Respawner& operator= (const Respawner&);
};


class Room;
class CreatureFactory;
class ItemFactory;
class MudContainer;


class CreatureRespawner : public Respawner {
public:
    CreatureRespawner(CreatureFactory* factory_, Room* room_, unsigned int delay_, const std::string& message_ = "");
    virtual void spawn();
private:
    const std::auto_ptr<CreatureFactory> factory;
    Room* room;
    std::string message;

    CreatureRespawner(const CreatureRespawner&);
    CreatureRespawner& operator=(const CreatureRespawner&);
};


class ItemRespawner : public Respawner {
public:
    ItemRespawner(ItemFactory* factory_, Room* room_, unsigned int delay_, const std::string& message_ = "");
    virtual void spawn();
private:
    const std::auto_ptr<ItemFactory> factory;
    Room* room;
    std::string message;

    ItemRespawner(const ItemRespawner&);
    ItemRespawner& operator=(const ItemRespawner&);
};


class ItemContainerRespawner : public Respawner {
public:
    ItemContainerRespawner(ItemFactory* factory_, MudContainer* container_, unsigned int delay_);
    virtual void spawn();
private:
    const std::auto_ptr<ItemFactory> factory;
    MudContainer* container;

    ItemContainerRespawner(const ItemContainerRespawner&);
    ItemContainerRespawner& operator=(const ItemContainerRespawner&);
};

}

#endif

